package com.qk.management.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.mapper.CourseMapper;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/7 20:52
 */
@Service
@SuppressWarnings("all")
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;


    @Override
    public PageResult<Course> Page(CourseDTO courseDTO) {
        PageHelper.startPage(courseDTO.getPage(), courseDTO.getPageSize());
        List<Course> list = courseMapper.list(courseDTO);
        Page<Course> page = (Page<Course>) list;
        return PageResult.<Course>builder()
                .total(page.getTotal())
                .rows(page.getResult())
                .build();
    }

    @Override
    public void add(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insert(course);
    }

    @Override
    public void delete(Integer id) {
        courseMapper.delete(id);
    }

    @Override
    public Course get(Integer id) {
        return courseMapper.selectById(id);
    }

    @Override
    public void update(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update(course);
    }

    @Override
    public List<Course> list() {
        return courseMapper.getList();
    }

    @Override
    public List<Course> listSubject(String subject) {
        return courseMapper.getListBySubject(subject);
    }
}
